package com.wtf.generator.controller;

import com.wtf.generator.common.sys.R;
import com.wtf.generator.common.utils.PageUtils;
import com.wtf.generator.model.dto.*;
import com.wtf.generator.model.vo.TemplateConfigVo;
import com.wtf.generator.service.WtfTemplateConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * date: 2022/6/18 10:59
 * @author linhuanyou
 * @email 496558736@qq.com
 * @version 1.0
 */
@Api(tags = "数据源代码生成模板配置操作")
@RestController
@RequestMapping("/template")
public class DsTemplateConfigController {

    @Autowired
    private WtfTemplateConfigService wtfTemplateConfigService;

    @ApiOperation(value = "获取模板配置(分页)")
    @GetMapping("/page")
    public R page(@Validated TemplatePageDTO templatePageDTO){
        PageUtils page = wtfTemplateConfigService.page(templatePageDTO);
        return R.ok(page);
    }

    @ApiOperation(value = "获取模板配置")
    @GetMapping("/list")
    public R list(@Validated TemplateListDTO templateListDTO){
        List<TemplateConfigVo> list = wtfTemplateConfigService.list(templateListDTO);
        return R.ok(list);
    }

    @ApiOperation(value = "新增模板配置")
    @PostMapping("/add")
    public R save(@RequestBody @Validated TemplateAddDTO templateAddDTO){
        int save = wtfTemplateConfigService.add(templateAddDTO);
        return R.ok();
    }

    @ApiOperation(value = "更新模板配置")
    @PostMapping("/update")
    public R update(@RequestBody @Validated TemplateUpdDTO templateUpdDTO){
        int update = wtfTemplateConfigService.update(templateUpdDTO);
        return R.ok();
    }

    @ApiOperation(value = "删除模板配置")
    @PostMapping("/del")
    public R remove(@RequestBody @Validated TemplateDelDTO templateDelDTO){
        int del = wtfTemplateConfigService.remove(templateDelDTO);
        return R.ok();
    }

}
